//
//  DoubleAttack.m
//  PacIsBack
//
//  Created by Simon André on 15/02/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "DoubleAttack.h"
#import "CharacterProtocol.h"
#import "BattleProtocol.h"
#import "BattleViewController.h"
#import "CharacterViewController.h"


@implementation DoubleAttack

@synthesize currentSource, currentTarget, currentBattle;

-(id) init{
	if (self = [super init]) {
		mpCost=100;
	}
	return self;
}

- (NSString*) shownName{
	NSString* name = @"Double Attack";
	return name;
}

- (NSInteger) mpCost{
	return mpCost;
}

- (void) secondPhase{
	[[[self currentBattle] controller] executeAttackFrom:[self currentSource] toTarget:[self currentTarget]];
	phase2Done = YES;
}

- (void) executeFrom:(id<CharacterProtocol>)source on:(id<CharacterProtocol>)target inBatte:(id<BattleProtocol>) battle{
	if ([source currentMP] >= [self mpCost]) {
		phase2Done = NO;
		[self setCurrentSource:source];
		[self setCurrentTarget:target];
		[self setCurrentBattle:battle];
		[source useMP:[self mpCost]];
		[[battle controller] executeAttackFrom:source toTarget:target];
	}
}

-(void) nextPhase{
	if (phase2Done) {
		phase2Done = NO;
		[[self currentSource] setHasPlayed:YES];
	}
	else {
		[self secondPhase];
	}
}

- (NSInteger) damagesProduced:(id<CharacterProtocol>) source on :(id<CharacterProtocol>) target{
	NSInteger originAttackPower = [source attackPower];
	NSInteger inflictedDamages = [target receiveAttack:originAttackPower];
	NSString* texte = [NSString stringWithFormat:@"%@%@%@%@%d%@",[source characterType],@" Attack ",[target characterType],@" for ",inflictedDamages, @" using Double Attack"];
	[[self currentBattle] showInfo:texte];
	return inflictedDamages;
}

- (void) dealloc{
	[self setCurrentBattle:nil];
	[self setCurrentSource:nil];
	[self setCurrentTarget:nil];
	[super dealloc];
}

@end
